<template>
  <div>
    <!-- v-if="!isCollection" -->
    <div v-if="!isCollection"
      class="box"
      @click="
        addLishi(),
          $router.push({
            path: '/xiangqing',
            query: { id: item?.r?.id || item?.note?.id || item?.r?.vc },
          })
      "
    >
      <div class="left">
        <van-image
          width="100rem"
          height="90rem"
          fit="cover"
          :src="item.r?.img || item.r?.p || item.note?.image_u"
        />
      </div>
      <div class="right">
        <h1>
          {{ item.r?.stdname || item.r?.n || item.r?.tips || item.note?.title||item?.note?.events[0]?.name }}
        </h1>
        <div class="xingrong">{{ item.r?.cookstory || item.r?.n }}</div>
        <div class="hz" v-if="item.r?.recommendation_tag">
          <p>{{ item.r?.recommendation_tag }}</p>
        </div>
        <div class="hz" v-if="!item.r?.recommendation_tag">
          <p>
            {{ item.note?.like_count || item.r?.collect_count_text }}
            <span v-if="item.note?.like_count">人收藏</span>
          </p>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import Vue from "vue";
import { Image as VanImage } from "vant";

Vue.use(VanImage);
export default {
  props: ["item", "itemt"],
  data() {
    return {
      make: [],
      itemts: JSON.parse(window.localStorage.getItem("itemts")) || [],
    };
  },
  computed: {
    isCollection: function () {
      const arr =
        this.itemts.filter((o) => {
          return o.ckid === this.item.cook_id;
        }) || [];
      return arr.length > 0 ? true : false;
    },
  },
  methods: {
    addLishi() {
      this.cookid =
        this.item.cook_id || this.item?.r?.id || this.item?.note?.id;
      // console.log("this.cookid", this.cookid);
      this.itemts = [{ ckid: `${this.cookid}` }, ...this.itemts];
      window.localStorage.setItem("itemts", JSON.stringify(this.itemts));
    },
  },

};
</script>

<style lang="scss" scoped>
.van-image {
  img {
    width: 100%;
    height: 100%;
    display: block;
    object-fit: cover;
  }
}
.box {
  display: flex;
  .right {
    width: 240rem;
    height: 100rem;
    position: relative;
    h1 {
      font-size: 16rem;
      font-weight: 700;
      margin: 15rem 0 0 10rem;
      color: #777;
    }
    .xingrong {
      // height: 30rem;
      width: 230rem;
      margin: 5rem 0 0 10rem;
      font-size: 12rem;
      overflow: hidden;
      -webkit-line-clamp: 3;
      display: -webkit-box;
      -webkit-box-orient: vertical;
    }
    .hz {
      position: absolute;
      bottom: 10rem;
      left: 10rem;
    }
  }
}
</style>
